package qaz.activity;

import java.util.ArrayList;

import qaz.adapter.IconNewsAdapter;
import qaz.adapter.NewsTitleAdapter;
import qaz.news.NewsTitle;
import qaz.news.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

public class ArticleActivity extends Activity {
	private int index;
	private ListView lvListArticle;
	private static TextView tvMarqueTitle;
	private NewsTitleAdapter newsAdapter;
	private ArrayList<NewsTitle> listArticle;
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.news_list_title_layout);
		lvListArticle = (ListView) findViewById(R.id.lv_list_title);
		listArticle = new ArrayList<NewsTitle>();
		ImageView imgHeader= (ImageView)findViewById(R.id.header_image);
		tvMarqueTitle=(TextView)findViewById(R.id.tv_marque);
		Bundle extras = getIntent().getExtras(); 
		if (extras != null) {
		    index = extras.getInt("INDEX");
		    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(36, 18);
		    imgHeader.setLayoutParams(layoutParams);		    
		    imgHeader.setImageResource(IconNewsAdapter.mThumbIds[index]);
		    tvMarqueTitle=(TextView)findViewById(R.id.tv_marque);
		    String t= extras.getString("HEADNAME");
		    //t=t.concat(IconNewsAdapter.name[index]);
		    tvMarqueTitle.setText(t);
		}
		for (int i = 0; i < 10; i++) {
			NewsTitle t = new NewsTitle("Article" + i);
					
			listArticle.add(t);
		}
		newsAdapter= new NewsTitleAdapter(this, R.layout.news_title_row, listArticle);
		lvListArticle.setAdapter(newsAdapter);
		lvListArticle.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				// TODO Auto-generated method stub
				Intent i= new Intent(getApplicationContext(),ContentViewActivity.class);
				i.putExtra("INDEX", index);
				i.putExtra("HEADNAME", tvMarqueTitle.getText().toString()+"-"+listArticle.get(arg2).getTitle());
				startActivity(i);
			}
		});
	}
}
